<template>
    <div class="nav-container">
        <div class="logo" @click="returnHome"></div>
        <div class="menu">
            <div v-for="item in menuItems" :key="item.icon" :class="{ active: isActive(item) }" class="menu-item"
                @click="setActive(item)">
                <div :class="'icon icon-' + item.icon"></div>
                <span class="text">{{ item.text }}</span>
            </div>
        </div>
        <div class="search"></div>
        <div class="user"></div>
    </div>
</template>
<script>
import router from '@/router';

export default {
    name: 'Navigator',
    components: {
    },
    methods: {
        returnHome() {
            router.push("/");
        },
        isActive(item) {
            return this.activeItem === item;
        },
        setActive(item) {
            this.activeItem = item;
        }
    },
    data() {
        return {
            activeItem: null,
            menuItems: [
                { icon: 'library', text: '书城' },
                { icon: 'posts', text: '帖子' },
                { icon: 'bookshelf', text: '书架' },
                { icon: 'cardnote', text: '笔记' },
                { icon: 'community', text: '社区' }
            ]
        }
    }
}
</script>
<style scoped>
.nav-container {
    width: 100%;
    height: 6vh;
    display: flex;
    background-color: #fff;
}

.logo {
    background-image: url('@/assets/img/nav/logo.png');
    background-size: cover;
    width: 10vw;
    cursor: pointer;
}

.menu {
    display: flex;
    height: 100%;
}

.menu-item {
    width: 54px;
    height: 44px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 30%;
    transition: 0.5s ease;
    cursor: pointer;

    &:hover {
        background-color: #d0d1d2;
    }

    .icon {
        width: 28px;
        min-height: 28px;
        background-size: cover;
        background-position: center;
    }

    .text {
        margin-top: 10px;
    }
}

.icon-library {
    background-image: url('@/assets/img/nav/library.png')
}

.icon-posts {
    background-image: url('@/assets/img/nav/posts.png')
}

.icon-bookshelf {
    background-image: url('@/assets/img/nav/bookshelf.png')
}

.icon-cardnote {
    background-image: url('@/assets/img/nav/cardnote.png')
}

.icon-community {
    background-image: url('@/assets/img/nav/community.png')
}

/* 选中状态的样式 */
.menu-item.active,
.menu-item:hover {
    background-color: #e7f7f8;
    color: black;
}

.search {}

.user {}
</style>